# Makefiles header
# OS   : Linux, QNX, Solaris, HPUX
# Tool : gcc or native complier
#
# This header is included into the individual
# makefiles for the runtime and samples
#
# Copyright (c) 2001-2012 McObject LLC.
# 
#
#

## Build control switches ---------------------------------
# Remove the comment from follows switches or type:
# make x64=on    	    - to build x64 version
# make SHOW_BUILD_LOG=on    - to see building progress
# make DEBUG=on             - to make a debug version of the runtime
# make OPTIMIZE=size        - to minimize the runtime size
# make OPTIMIZE=speed       - to maximize the runtime perfomance
# make STATIC=on            - to enable static linkage of executables
# make HOST_PLATFORM=       - to build tools and utilites for specified host platform
# make HOST_FLAGS=          - to specify additional flags for host platform
# make TARGET_PLATFORM=     - to build runtime and samples for specified target platform (mipsel,arm,etc)
# make TARGET_FLAGS=        - to specify additional flags for target platform (ex -mcpu=XXXX)
# make TARGET_OS_HINT=      - to tune up the runtime for specified target OS (ex. uCLinux or LynxOS)
# make MCO_LIB_DYNAMIC=     - to build dynamic version (.so) of the runtime
# make MCO_LIB_STATIC=      - to build static version (.a) of the runtime
# make TARGET_ARCH=         - to override target's and/or
# make HOST_ARCH=           - host's cpu architecture
#                             possible values: arm|mips|ix86|ppc|m68k|sparc64
# make TARGET_CPUNO=        - to set number of cpu on host's or target's. 
# make HOST_CPUNO=          - Default setting is 2 to enforce SMP behaviour.
# make SAMPLE_STRG=         - set database storage for a sample (memory or disk). Default is memory 
#                             Note: applicable to samples only. Ignored in other cases.
# make MCO_FS=              - to build samples for specified file system. Default depends on TARGET_PLATFORM 
# make MCO_USE_ARCH_SFX=    - to enable (on) or disable (off) name suffixing of object and binary directories. 
#                             This option is useful when you need to build binaries for different architectures
#                             in the same source tree. Disabled by default.


SHOW_BUILD_LOG=on
DEBUG=on
#OPTIMIZE=speed
#OPTIMIZE=size
#STATIC=on
#HOST_PLATFORM=
#HOST_FLAGS=-g
#TARGET_PLATFORM=mipsel-linux|arm-linux
#TARGET_OS_HINT=uCLinux
#TARGET_FLAGS=-mips2|-m5307
#TARGET_FLAGS=-g
#MCO_LIB_DYNAMIC=enabled
#MCO_LIB_DYNAMIC=disabled
#MCO_LIB_STATIC=enabled
#MCO_LIB_STATIC=disabled
#TARGET_ARCH=arm|mips|ix86|ppc|m68k|sparc64
#TARGET_ARCH=ix86
#HOST_ARCH=arm|mips|ix86|ppc|m68k|sparc64
#HOST_ARCH=ix86
HOST_CPUNO  ?= 2
TARGET_CPUNO?= 2
#SAMPLE_STRG=memory|disk
#MCO_FS=ucos|w32|funi|fu98|<custom>
#MCO_DIRECT_PTR=on|off
#MCO_USE_ARCH_SFX=on
#MCO_USE_ARCH_SFX=off

## Platforms ----------------------------------------------
BUILD_PLATFORM   := $(shell uname -s)
BUILD_ARCH       := $(shell uname -m | sed -e's/i.86/ix86/' -e's/^[xX]86.*_64/ix86_64/' -e's/^[xX]86.*/ix86/' -e's/sun4u/sparc64/' -e's/arm.*/arm/' -e's/sa110/arm/' -e's/mips.*/mips/' -e's/ppc.*/ppc/' -e's/powerpc.*/ppc/' -e's/m68k.*/m68k/')

AUTODETECTED_PLATFORM := $(BUILD_PLATFORM)

ifeq ($(AUTODETECTED_PLATFORM),Darwin)
BUILD_PLATFORM   := Linux
BUILD_ARCH := ix86_64
TEST_FILE = false
else
TEST_FILE = test -f
endif

ifeq ($(findstring CYGWIN_NT, $(AUTODETECTED_PLATFORM)),CYGWIN_NT)
TEST_FILE = false
endif

HOST_PLATFORM    ?= $(BUILD_PLATFORM)
TARGET_PLATFORM  ?= $(BUILD_PLATFORM)
ENV_CC           := $(CC)
ENV_CXX          := $(CXX)

ifeq ($(BUILD_ARCH),ix86_64)
ifneq ($(x64),on)
BUILD_ARCH       := ix86
endif
endif


## Common build variables ---------------------------------------------

SAMPLE           ?= no                           # must be defined in sample makefile 
SAMPLE_STRG      ?= memory                       # default sample storage mode "in-memory"
SAMPLE_INCLUDE    = -I$(MCO_ROOT)/platform
MEMORY_SFX       := 
DISK_SFX         := -d

ifeq ($(MCO_USE_ARCH_SFX),on)
BUILD_ARCH_SFX   := -$(BUILD_ARCH)
MCO_ARCH_SFX      = -$($(MCO_SIDE)_ARCH)
else
BUILD_ARCH_SFX   :=
MCO_ARCH_SFX     := 
endif

MCO_INCLUDE       = -I$(MCO_ROOT)/include  -I$(MCO_ROOT)/include/ha
MCO_SQL_INCLUDE   = -I$(MCO_ROOT)/include/sql
MCO_ODBC_INCLUDE  = -I$(MCO_ROOT)/include/sql/odbc

MCO_TARGET        = $(MCO_ROOT)/target
MCO_HOST          = $(MCO_ROOT)/host
MCO_ODBC          = $(MCO_ROOT)/odbc

ifeq "$(MCO_DIRECT_PTR)" "on"
MCO_BIN           = $(MCO_$(MCO_SIDE))/bin.dptr$(MCO_ARCH_SFX)
else
MCO_BIN           = $(MCO_$(MCO_SIDE))/bin$(MCO_ARCH_SFX)
endif

MCO_BIN           = $(MCO_$(MCO_SIDE))/bin$(MCO_ARCH_SFX)
MCO_BIN_SO        = $(MCO_$(MCO_SIDE))/bin$(MCO_ARCH_SFX).so
MCO_ODBC_BIN      = $(MCO_ODBC)/bin$(MCO_ARCH_SFX)
MCO_ODBC_BIN_SO   = $(MCO_ODBC)/bin$(MCO_ARCH_SFX).so
MCO_LIB_SRC       = $(MCO_TARGET)/mcolib
MCO_BUILD_LOG_DIR = $(MCO_ROOT)/_build-logs$(MCO_ARCH_SFX)
MCOCOMP           = $(MCO_HOST)/bin$(BUILD_ARCH_SFX)/mcocomp
MCORCOMP          = $(MCO_HOST)/bin$(BUILD_ARCH_SFX)/mcorcomp

MCO_CFG_SUFFIX_A  = .a
MCO_CFG_SUFFIX_SO = .so
MCO_LOGFILE_SFX  := .log

CHECK_SUFFIX     := debug
ST_SUFFIX        := st
EVAL_SUFFIX      := eval
SQL_SUFFIX       := sql

MCO_CFG_OVERRIDE := # clear initialy 
CHECKFLAGS       := -DMCO_CONFIG_OVERRIDE_CHECKLEVEL -DMCO_CFG_CHECKLEVEL_1 -DMCO_CFG_CHECKLEVEL_2 -DMCO_CFG_CHECKLEVEL_3
RELEASEFLAGS     := # just as specified in mcocfg.h configuration file

MCO_VERSION       = test -f $(MCO_ROOT)/include/version && cat $(MCO_ROOT)/include/version
MCO_SQLLIB_EXISTS = test -f $(MCO_BIN)/libmcolib_sql.a -o -f $(MCO_BIN_SO)/libmcolib_sql.so && echo present

MCO_RTODBC        = -L$(MCO_ODBC)/bin -L$(MCO_BIN) -lmcoodbc$(MCO_RTCHECK)
MCO_RTSQL         = -lmcosql$(MCO_RTCHECK) -lmcoapi$(MCO_RTCHECK)
MCO_RTRSQL        = -lmcorsql$(MCO_RTCHECK)
MCO_RTLIB         = 
MCO_RPCLIB        = -lmcorpc$(MCO_RTCHECK)

ifdef DEBUG
MCO_RTCHECK      := _$(CHECK_SUFFIX)
else
MCO_RTCHECK      :=
endif

ifdef MCO_OBJ_DIR
MCO_OBJ_DIR      := $(addprefix obj,$(MCO_OBJ_DIR))
else
MCO_OBJ_DIR      := obj
endif

ifeq "$(MCO_DIRECT_PTR)" "on"
MCO_CFG_OVERRIDE := -DMCO_CFG_USE_DIRECT_POINTERS
ifeq "$(SAMPLE_STRG)" "disk"
#override SAMPLE_STRG      := memory

force:
	@echo "DirectPointers config is not supported for this application($(MCO_TITLE) diskV)"

endif
endif 

ifeq "$(SAMPLE)" "yes"
MCO_INCLUDE      += $(SAMPLE_INCLUDE) -I$(MCO_OBJ_DIR)
MCOCOMP          += -P$(MCO_OBJ_DIR)/
ifeq "$(SAMPLE_SQL)" "yes"
MCO_INCLUDE      += $(MCO_SQL_INCLUDE)
MCOCOMP_SQL_F    := -sql
MCO_RTLIB        += $(MCO_RTSQL)
ifeq "$(SAMPLE_RSQL)" "yes"
MCO_RTLIB        += $(MCO_RTRSQL)
endif
ifeq ($(shell $(MCO_SQLLIB_EXISTS)),present)
MCO_RTCORE       := -lmcolib$(MCO_RT)_sql$(MCO_RTCHECK)
else
MCO_RTCORE       := -lmcolib$($(MCO_RT):_sql=)$(MCO_RTCHECK)
endif
else
MCOCOMP_SQL_F    :=
MCO_RTCORE       := -lmcolib$(MCO_RT)$(MCO_RTCHECK)
endif

MCO_RTLIB        += $(MCO_RTCORE)

ifeq "$(SAMPLE_STRG)" "disk"
MCO_LOGFILE_SFX  := $(addprefix $(DISK_SFX),$(MCO_LOGFILE_SFX))
MCO_OBJ_DIR      := $(addsuffix $(DISK_SFX),$(MCO_OBJ_DIR))
MCO_VT           := dsk
SAMPLE_FLAGS     := -DDISK_DATABASE -DDB_LOG_TYPE=REDO_LOG
MCOCOMP_STRG_F   := -persistent
STRG_SFX         := $(DISK_SFX)
else
MCO_LOGFILE_SFX  := $(addprefix $(MEMORY_SFX),$(MCO_LOGFILE_SFX))
MCO_OBJ_DIR      := $(addsuffix $(MEMORY_SFX),$(MCO_OBJ_DIR))
MCO_VT           := mem
SAMPLE_FLAGS     := -DMEMORY_DATABASE
MCOCOMP_STRG_F   := 
STRG_SFX         := $(MEMORY_SFX)
endif
else
MCO_OBJ_DIR_SFX  :=
endif

MCO_RTLIB        += -lmcovt$(MCO_VT)$(MCO_RT)$(MCO_RTCHECK)

ifeq ($(MCO_VT), dsk)
 MCO_RTSQL += -lmcoseridsk$(MCO_RTCHECK)
else
 MCO_RTSQL += -lmcoseri$(MCO_RTCHECK)
endif

ifeq ($(MCOCOMP_SQL_F), -sql)
 ifeq ($(MCO_VT), dsk)
  MCO_RTLIB += -lmcoseridsk$(MCO_RTCHECK)
 else
  MCO_RTLIB += -lmcoseri$(MCO_RTCHECK)
 endif
endif

#  Default FS setting
ifeq ($(TARGET_OS_HINT),LynxOS)
DEFAULT_FS_LINUX          = uni
else
DEFAULT_FS_LINUX          = u98
endif
DEFAULT_FS_WIN32          = w32
DEFAULT_FS_SOLARIS        = u98
DEFAULT_FS_QNX            = u98
DEFAULT_FS_HPUX           = u98
DEFAULT_FS_ADS            = ucos
DEFAULT_FS_OS21           = u98

MCO_FS                   ?= $(DEFAULT_FS$(subst -D,,$(PLATFORM_ID)))
MCO_FS_LIB		  = -lmcof$(strip $(MCO_FS))
ifeq ($(MCO_VT), dsk)
MCO_RTLIB                += $(MCO_FS_LIB)$(MCO_RTCHECK)
endif

#  Default SYNC setting
ifeq ($(TARGET_OS_HINT),LynxOS)
DEFAULT_SYNC_LINUX_SHM   := lynx
DEFAULT_SYNC_LINUX_CNV   := lynxp
else
DEFAULT_SYNC_LINUX_SHM   := lnx   # possible alternative is lnxs5 
DEFAULT_SYNC_LINUX_CNV   := lnxp  # possible alternative is lnxsp 
endif
DEFAULT_SYNC_WIN32       := w32
DEFAULT_SYNC_SOLARIS     := sun
DEFAULT_SYNC_QNX         := qnxp
DEFAULT_SYNC_HPUX        := hpuxp
DEFAULT_SYNC_ADS         := ucsn # possible alternatives are ucos ucsn
DEFAULT_SYNC_ECOS        := ecos
DEFAULT_SYNC_OS21        := os21

ifeq ($(SHM_APP),yes)
DEFAULT_SYNC_LINUX        = $(DEFAULT_SYNC_LINUX_SHM)
else
DEFAULT_SYNC_LINUX        = $(DEFAULT_SYNC_LINUX_CNV)
endif

MCO_SYNC                 ?= $(DEFAULT_SYNC$(subst -D,,$(PLATFORM_ID)))
MCO_SYNC_LIB              = -lmcos$(strip $(MCO_SYNC))
MCO_RTLIB                += $(MCO_SYNC_LIB)$(MCO_RTCHECK)

# Default SHM settings
DEFAULT_SHM_LINUX        := ipc
DEFAULT_SHM_WIN32        := w32
DEFAULT_SHM_SOLARIS      := ipc
DEFAULT_SHM_QNX          := psx
DEFAULT_SHM_HPUX         := ipc
DEFAULT_SHM_ADS          := # none
DEFAULT_SHM_ECOS         := conv
DEFAULT_SHM_OS21         := # none

ifeq ($(SHM_APP),yes)
MCO_MEM                  ?= $(DEFAULT_SHM$(subst -D,,$(PLATFORM_ID)))
else
MCO_MEM                  ?= conv
endif

ifneq ($(strip MCO_MEM),)
MCO_MEM_LIB               = -lmcom$(strip $(MCO_MEM))
MCO_RTLIB                += $(strip $(MCO_MEM_LIB))$(MCO_RTCHECK)
endif

#  Default RTL settings
MCO_MISC                 ?= wrt # Use runtime library. Default. 
MCO_MISC                 ?= nrt # Do not use runtime library.

#  Default transaction manager
MCO_TMGR                 ?= mursiw # possible values are "exlc" (exclusive) or "mursiw" (multiple readers single writer) or mvcc (multiverioned concurrent control)
MCO_TMGR_LIB              = -lmcot$(strip $(MCO_TMGR))
MCO_RTLIB                += $(MCO_TMGR_LIB)$(MCO_RTCHECK) $(MCO_RTCORE)

MCO_MISC_LIB              = -lmcou$(strip $(MCO_MISC))
MCO_RTLIB                += $(MCO_MISC_LIB)$(MCO_RTCHECK)

# rt variants
MCO_OBJ_VSFX     := # Variation suffix 
MCO_BUILDRT_SFX_M:= # no modification suffix initially
MODFLAGS         := # no modification flags initially

ifeq ($(MCO_BUILD_RT_DEBUG),on)
MCO_CFG_OVERRIDE += $(CHECKFLAGS)
MCO_FS_LIB	 := $(addsuffix _$(CHECK_SUFFIX), $(MCO_FS_LIB))
MCO_SYNC_LIB     := $(addsuffix _$(CHECK_SUFFIX), $(MCO_SYNC_LIB))
MCO_MEM_LIB      := $(addsuffix _$(CHECK_SUFFIX), $(MCO_MEM_LIB))
DEBUG            :=on
ifeq ($(MCO_BUILDRT_SFX_C),)
MCO_BUILDRT_SFX_C:= _$(CHECK_SUFFIX)
else
MCO_BUILDRT_SFX_C:= $(addsuffix _$(CHECK_SUFFIX), $(MCO_BUILDRT_SFX_C))
endif
MCO_OBJ_DIR      := $(addsuffix -$(CHECK_SUFFIX), $(MCO_OBJ_DIR))
MCO_TITLE        := $(addsuffix -$(CHECK_SUFFIX), $(MCO_TITLE))
else
MCO_CFG_OVERRIDE+= $(RELEASEFLAGS)
endif

ifeq ($(MCO_BUILD_RT_EVAL),on)

MCO_CFG_OVERRIDE += -DMCO_CFG_TRLIMIT=1000000 

MCO_BUILDRT_SFX_E:= _$(EVAL_SUFFIX)
MCO_OBJ_DIR      := $(addsuffix -$(EVAL_SUFFIX), $(MCO_OBJ_DIR))
MCO_TITLE        := $(addsuffix -$(EVAL_SUFFIX), $(MCO_TITLE))
endif

ifeq ($(MCO_BUILD_RT_VTDSK_SPINS),on)
MCO_OBJ_VSFX     := _spn
MCO_BUILDRT_SFX_M:= _spn
MODFLAGS         := -DMCO_TUNE_SPINLOCKED_DISKPOOL
endif

MCO_BUILDRT_SFX  := $(MCO_BUILDRT_SFX_M)$(MCO_BUILDRT_SFX_C)$(MCO_BUILDRT_SFX_E)

ifeq ($(MCO_SIDE),HOST)
LDFLAGS       += $(STATICF)
LDCXXFLAGS    += $(STATICF)
endif

##  Testing arch file ------------------------------------------------------
ifneq ($(SHOW_X64_ARCH),on)

xArchBoth = off
ifeq ($(shell test -f $(MCO_ROOT)/x32_arch_binaries && echo present),present)
x32Arch = on
else
x32Arch = off
endif
ifeq ($(shell test -f $(MCO_ROOT)/x64_arch_binaries && echo present),present)
x64Arch = on
else
ifeq ($(x32Arch),off)
x32Arch = on
x64Arch = on
xArchBoth = on
else
x64Arch = off
endif
endif

ifeq ($(x64),)
ifeq ($(xArchBoth),off)
ifeq ($(x64Arch),off)
x64 = off
else
x64 = on
endif 
endif
else

## Test binary compatibility
ifeq ($(x64),on)

ifeq ($(x64Arch),off)
$(error 64bit app build is not supported.)
endif

else

ifeq ($(x32Arch),off)
$(error 32bit app build is not supported.)
endif

endif
 
endif 
endif
## end of arch testing -------------------------------------------------

## Platform-dependent variables ----------------------------------------

# Common settings
NMAKE             = nmake.bat
RMFILE            = rm -f
RMDIR             = rm -rf
CPFILE            = cp -f
AR                = ar
ARFLAGS           = rc
STRIP             = strip
BISON_           := $(shell which bison > /dev/null 2>&1; if [ 1 -eq 0 ]; then echo bison -d; fi )
YACC_            := $(shell which yacc > /dev/null 2>&1; if [ 1 -eq 0 ]; then echo yacc; fi )
ifeq ($(strip $(BISON_)),)
ifneq ($(strip $(YACC_)),)
BISON            := $(YACC_)
else
BISON            :=
endif
else
BISON            := $(BISON_)
endif

ARCH_FLAGS        =
COMMONFLAGS       = $(DEBUGFLAGS) $(OPTIMIZEFLAGS) $($(MCO_SIDE)_FLAGS) $(SAMPLE_FLAGS) $(MODFLAGS)
CFLAGS            = $(COMMONFLAGS) $(PLATFORM_ID) $(ARCH_FLAGS) -Wall # -pedantic
CXXFLAGS          = $(COMMONFLAGS) $(PLATFORM_ID) $(ARCH_FLAGS) -fexceptions $(CXXTEMPLATEDEPTHF) -Wall
SOCFLAGS          = $(PICF) $(PLATFORM_ID) $(ARCH_FLAGS) 
SOCXXFLAGS        = $(PICF) $(PLATFORM_ID) $(ARCH_FLAGS) 
SOLDFLAGS         = $(COMMONFLAGS) $(PICF) $(SHAREDF)
LDFLAGS           = $(COMMONFLAGS)
LDCXXFLAGS        = $(COMMONFLAGS)
#STATIC            = on
ifdef STATIC
LDFLAGS          += $(STATICF)
LDCXXFLAGS       += $(STATICF)
endif
LDFLAGS           += -L$(MCO_BIN)
LDCXXFLAGS        += -L$(MCO_BIN)  -fexceptions

MCO_LIB_DYNAMIC  ?= enabled
MCO_LIB_STATIC   ?= enabled
MCO_SHAREDMEM    ?= enabled

ifndef GENERATOR
CC               ?= gcc
CXX              ?= g++
LD                = $(CC)
LDCXX             = $(CXX)
else
CC = echo
CXX = echo
LD = echo
LDCXX = echo
AR = echo "OUTAR"; touch
ARFLAGS = 
#LDFLAGS =
endif

ifndef GENERATOR
LDOUTPUTF         = -o
LDCXXOUTPUTF      = -o
CCOUTPUTF         = -o
CXXOUTPUTF        = -o
else
LDOUTPUTF         = ;echo "OUTLD"; touch
LDCXXOUTPUTF      = ;echo "OUTLD"; touch
CCOUTPUTF         = ; touch
CXXOUTPUTF        = ; touch
endif
LDSTRIPF          = -s
LDCXXSTRIPF       = -s
CCCOMPF           = -c
CXXCOMPF          = -c
DEBUGF            = -g
OPTIMIZEF_SIZE    = -Os
OPTIMIZEF_SPEED   = -O3
STATICF           = -static
SHAREDF           = -shared
PICF              = -fPIC
X32F             := -m32
X64F             := -m64
CXXTEMPLATEDEPTHF:= -ftemplate-depth-99

# platform-dependent overrides
SETTINGS_APPLIED  = no
FAMILY_PLATFORM   = nix

ifeq ($(BUILD_PLATFORM),Linux)

ifeq ($(MCO_SIDE)-$(TARGET_OS_HINT),TARGET-eCos)
INSTALL_DIR    = $$(INSTALL_DIR)
ifeq ($(INSTALL_DIR),)
$(error Error: no path to ECOS installation given. Please type "make INSTALL_DIR=..." to set the path)
endif

include $(INSTALL_DIR)/include/pkgconf/ecos.mak
$(MCO_SIDE)_PLATFORM = $(ECOS_COMMAND_PREFIX)
endif # TARGET-eCos

ifeq ($(BUILD_PLATFORM),$($(MCO_SIDE)_PLATFORM))
$(MCO_SIDE)_ARCH  = $(shell echo $(BUILD_ARCH) | sed -e's/i.86/ix86/' -e's/^[xX]86.*_64/ix86_64/' -e's/^[xX]86.*/ix86/' -e's/sun4u/sparc64/' -e's/arm.*/arm/' -e's/sa110/arm/' -e's/mips.*/mips/')
else
$(MCO_SIDE)_ARCH  = $(shell echo $($(MCO_SIDE)_PLATFORM) | cut -d'-' -f1 | sed -e's/ppc.*/ppc/' -e's/powerpc.*/ppc/' -e's/m68k.*/m68k/' -e's/i.86/ix86/' -e's/^[xX]86.*/ix86/' -e's/sun4u/sparc64/' -e's/arm.*/arm/' -e's/sa110/arm/' -e's/mips.*/mips/')
endif

ifneq ($($(MCO_SIDE)_CPUNO),1)
ARCH_FLAGS       += -D_SMP
endif

ifeq ($(findstring -mthumb,$($(MCO_SIDE)_FLAGS)),-mthumb)
ARCH_FLAGS       += -D_ARM_THUMB
endif

ifeq ($($(MCO_SIDE)_ARCH),ia64)
ARCH_FLAGS       += -D_ITANIUM
x64 ?= on
endif

ifeq ($($(MCO_SIDE)_ARCH),ix86_64)
x64 ?= on
ifeq ($(x64),on)
ARCH_FLAGS       += -D_Ix86
else
$(MCO_SIDE)_ARCH  = ix86
endif
endif

ifeq ($($(MCO_SIDE)_ARCH),ix86)
ARCH_FLAGS       += -D_Ix86
endif
ifeq ($($(MCO_SIDE)_ARCH),mips)
ARCH_FLAGS       += -D_MIPS32
TARGET_FLAGS     += -mips2
endif
ifeq ($($(MCO_SIDE)_ARCH),ppc)
ARCH_FLAGS       += -D_PPC32
endif
ifeq ($($(MCO_SIDE)_ARCH),m68k)
ARCH_FLAGS       += -D_M68K
endif
ifeq ($($(MCO_SIDE)_ARCH),arm)
ARCH_FLAGS       += -D_ARM32
endif
ifeq ($($(MCO_SIDE)_ARCH),sparc64)
ARCH_FLAGS       += -D_SPARC64
endif
ifeq ($($(MCO_SIDE)_ARCH),sh4)
ARCH_FLAGS       += -D_SH4
endif
ifeq ($($(MCO_SIDE)_ARCH),tile)
ARCH_FLAGS       += -D_TILE
x64               = on
X32F             :=
X64F             :=
CXXTEMPLATEDEPTHF:=
PLATFORMLIB       = -lm
endif


PLATFORM_ID    = -D_LINUX
PTHREADLIB     = 
PLATFORMLIB    = -lpthread
SOCKETLIB      =
STATIC         = on

ifneq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
AR             = $($(MCO_SIDE)_PLATFORM)-ar
STRIP          = $($(MCO_SIDE)_PLATFORM)-strip
CC             = $($(MCO_SIDE)_PLATFORM)-gcc
CXX            = $($(MCO_SIDE)_PLATFORM)-g++
endif

ifeq ($(TARGET_OS_HINT),uCLinux)
PLATFORMLIB   += -lc
LDFLAGS       += -elf2flt
CFLAGS        += -D__UCLINUX
CXXFLAGS      += -D__UCLINUX
SOCFLAGS      += -D__UCLINUX
SOCXXFLAGS    += -D__UCLINUX
endif

ifeq ($(TARGET_OS_HINT),LynxOS)
PTHREADLIB     =
PLATFORMLIB    =
MCO_CFG_OVERRIDE += -DMCO_CONFIG_OVERRIDE_WCHAR
LDFLAGS       += -mthreads -L$(ENV_PREFIX)/lib/thread
LDCXXFLAGS  += -mthreads
CFLAGS        += -D__LYNX
CXXFLAGS      += -D__LYNX
SOCFLAGS      += -D__LYNX
SOCXXFLAGS    += -D__LYNX
endif

ifeq ($(MCO_SIDE)-$(TARGET_OS_HINT),TARGET-eCos)
ifeq ($(ECOS_COMMAND_PREFIX),)
ARCH_FLAGS     += -D_Ix86
endif

ifneq ($(wildcard $(INSTALL_DIR)/include/pkgconf/fs_*.h),)
ECOS_FS_F      := -D_ECOS_FS_PRESENT
else
ECOS_FS_F      := -D_ECOS_FS_ABSENT
NFS            := on
endif

ifneq ($(wildcard $(INSTALL_DIR)/include/pkgconf/net_freebsd_stack.h),)
ECOS_NET_F     := -D_ECOS_NET_PRESENT -D__ECOS
else
ECOS_NET_F     := -D_ECOS_NET_ABSENT
NN             := on
endif

ifneq ($(wildcard $(INSTALL_DIR)/include/pkgconf/memalloc.h),)
ECOS_MALLOC_F  := -D_ECOS_MALLOC_PRESENT
else
ECOS_MALLOC_F  := -D_ECOS_MALLOC_ABSENT
NMALLOC        := on
endif

#no shared memory support
NSHAREDMEM     := on

ifeq ($(PRJ_TYPE)-$(PRJ_F_CPP),APP-YES)
CC             := $(ECOS_COMMAND_PREFIX)g++
else
CC             := $(ECOS_COMMAND_PREFIX)gcc
endif
CXX            := $(ECOS_COMMAND_PREFIX)g++
AR             := $(ECOS_COMMAND_PREFIX)ar
STRIP          := $(ECOS_COMMAND_PREFIX)strip
ARCH_FLAGS     += -D_ECOS $(ECOS_FS_F) $(ECOS_NET_F) $(ECOS_MALLOC_F) -I$(INSTALL_DIR)/include $(ECOS_GLOBAL_CFLAGS)
LDFLAGS        := -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld $(ECOS_GLOBAL_LDFLAGS)
LDCXXFLAGS     := $(LDFLAGS)
PLATFORMLIB    :=
PLATFORM_ID     = -D_ECOS
MCO_CFG_OVERRIDE+= -DMCO_CONFIG_OVERRIDE_WCHAR
MCO_LIB_DYNAMIC = disabled
JAVA           :=off
ifeq ($(OPTIMIZEF_SPEED),-O3)
OPTIMIZEF_SPEED = -O2
endif
endif # TARGET-eCos
## Setting up x64 defines --------------------------------

ifeq ($(gcov),on)
DEBUG=on
endif

ifeq ($(x64),on)
ifndef DEBUG
ifeq ($(OPTIMIZEF_SPEED),-O3)
OPTIMIZEF_SPEED = -O2
endif
endif

## if MontaVista CGE
ifneq ($(shell uname -a | grep mvlcge ),)

ifndef DEBUG
ifneq ($(OPTIMIZEF_SPEED),-O0)
OPTIMIZEF_SPEED = -O1
endif
endif

endif
## ----------------------------------------------

ifneq ($($(MCO_SIDE)_ARCH),ia64)

CXXFLAGS      += $(X64F)
CFLAGS        += $(X64F)
SOLDFLAGS     += $(X64F) 
SOCXXFLAGS    += $(X64F)
LDFLAGS       += $(X64F) 
LDCXXFLAGS    += $(X64F) 
endif 
 
else

ifeq ($(BUILD_PLATFORM),$($(MCO_SIDE)_PLATFORM))
CXXFLAGS      += $(X32F)
CFLAGS        += $(X32F)
SOLDFLAGS     += $(X32F) 
SOCXXFLAGS    += $(X32F)
LDFLAGS       += $(X32F) 
LDCXXFLAGS    += $(X32F) 
endif 

endif 

## -------------------------------------------------------

SETTINGS_APPLIED=yes

endif

ifeq ($(findstring CYGWIN_NT, $(BUILD_PLATFORM)),CYGWIN_NT)

ifeq ($(TARGET_OS_HINT),OS21)

PLATFORM_ID    = -D_OS21
PTHREADLIB     = 
PLATFORMLIB    =
SOCKETLIB      = 
COMMONFLAGS    = 
MCO_LIB_DYNAMIC= disabled

ifneq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
AR             = $($(MCO_SIDE)_PLATFORM)-ar
STRIP          = $($(MCO_SIDE)_PLATFORM)-strip
CC             = $($(MCO_SIDE)_PLATFORM)-gcc
CXX            = $($(MCO_SIDE)_PLATFORM)-g++
endif

else

CC             = gcc
CXX            = g++
PLATFORM_ID    = -D_LINUX
PTHREADLIB     = -lpthread
PLATFORMLIB    =
SOCKETLIB      = 
COMMONFLAGS    += -I.
ARCH_FLAGS    += -D_Ix86

MCO_LIB_DYNAMIC= disabled
SHAREDF        = --dll 
SOFLAGS       += --export-all-symbols -lkernel32

FAMILY_PLATFORM=win
endif

SETTINGS_APPLIED=yes
endif

ifeq ($(gcov),on)
ifneq ($(MCO_SIDE),HOST)
CFLAGS        += -fprofile-arcs -ftest-coverage
CXXFLAGS      += -fprofile-arcs -ftest-coverage
PLATFORMLIB   += -lgcov
endif
endif

ifeq ($(BUILD_PLATFORM),QNX)

CFLAGS        += $(MCO_INCLUDE)
CXXFLAGS      += $(MCO_INCLUDE)
PLATFORM_ID    = -D_QNX
PTHREADLIB     =
PLATFORMLIB    = -lm
SOCKETLIB      = -lsocket

ifeq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
else
AR             = nto$($(MCO_SIDE)_PLATFORM)-ar
STRIP          = nto$($(MCO_SIDE)_PLATFORM)-strip
CC             = nto$($(MCO_SIDE)_PLATFORM)-gcc
CXX            = nto$($(MCO_SIDE)_PLATFORM)-g++
endif

SETTINGS_APPLIED=yes
endif

ifeq ($(BUILD_PLATFORM),SunOS)

PLATFORM_ID    = -D_SOLARIS
PTHREADLIB     = -lpthread
PLATFORMLIB    = -lnsl
ifneq ($(MCO_SIDE),HOST)
OPTIMIZEF_SPEED = -O3
PLATFORMLIB   += -lrt
endif 

STATICF        =
SOCKETLIB      = -lsocket
SHAREDF        = -G
CFLAGS        += -DMCO_STRICT_ALIGNMENT
CXXFLAGS      += -DMCO_STRICT_ALIGNMENT

ifeq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
CC            := gcc
CXX           := g++
endif

BUILD_ARCH=$(shell uname -p)
$(MCO_SIDE)_ARCH  = $(shell echo $(BUILD_ARCH) | sed -e's/i.86/ix86/' -e's/^[xX]86.*/ix86/' -e's/sun4u/sparc64/' )

ifeq ($($(MCO_SIDE)_ARCH),ix86)
ARCH_FLAGS       += -D_Ix86
SOLDFLAGS        += -lrt
endif
ifeq ($($(MCO_SIDE)_ARCH),sparc)
ARCH_FLAGS       += -D_SPARC
CFLAGS        += -Wa,-xarch=v8plus
CXXFLAGS      += -Wa,-xarch=v8plus
SOCFLAGS      += -Wa,-xarch=v8plus
SOCXXFLAGS    += -Wa,-xarch=v8plus
endif

ifeq ($(x64),on)
CXXFLAGS      += $(X64F)
CFLAGS        += $(X64F)
SOLDFLAGS     += $(X64F) 
SOCXXFLAGS    += $(X64F)
LDFLAGS       += $(X64F) 
LDCXXFLAGS    += $(X64F) 
STATICF        =
else
CXXFLAGS      += $(X32F)
CFLAGS        += $(X32F)
SOLDFLAGS     += $(X32F) 
SOCXXFLAGS    += $(X32F)
LDFLAGS       += $(X32F) 
LDCXXFLAGS    += $(X32F) 
ifeq ($(MCO_DIRECT_PTR),on)
 MCO_LARGE_DATABASE_SUPPORT:=off
 OPTIMIZEF_SPEED = -O0
endif
endif 

ifeq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
SETTINGS_APPLIED=yes
endif

endif

ifeq ($(BUILD_PLATFORM),HP-UX)

ifeq ($(BUILD_ARCH),ia64)
ARCH_FLAGS     += -D_ITANIUM
endif

PLATFORM_ID    := -D_HPUX
PTHREADLIB     := -lpthread
PLATFORMLIB    := -lrt 
SOCKETLIB      := 
SHAREDF        := -lrt -shared
OPTIMIZEF_SPEED:= -O2
PICF            =
HOST_FLAGS     += -DHAVE_ALLOCA_H
CXXFLAGS       = $(COMMONFLAGS) $(PLATFORM_ID) $(ARCH_FLAGS) -DMCO_STRICT_ALIGNMENT
# -D_XOPEN_SOURCE_EXTENDED
# -D_INCLUDE__STDC_A1_SOURCE 
CFLAGS         = $(COMMONFLAGS) $(PLATFORM_ID) $(ARCH_FLAGS) -DMCO_STRICT_ALIGNMENT
# -D_XOPEN_SOURCE_EXTENDED 
 
# if compiler was not defined prefer native compiler instead of GNU
ifeq ($(ENV_CC),)
CC             := cc
endif
ifeq ($(ENV_CXX),)
CXX            := aCC
endif

ifeq ($(CC),gcc)
ifeq ($(x64),on)
CFLAGS        += -mlp64
SOLDFLAGS     += -mlp64 
LDFLAGS       += -mlp64 
endif 
endif

ifeq ($(CC),g++)
ifeq ($(x64),on)
CXXFLAGS      += -mlp64
SOCXXFLAGS    += -mlp64
LDCXXFLAGS    += -mlp64 
endif 
endif

ifeq ($(CC),cc)
STATICF        = -N
SHAREDF        = -b -lrt
CFLAGS        += +z -Ae -Agcc

ifeq ($(x64),on)
LD	       = $(CXX) # using aCC as linker for all x64 build on HPUX
CFLAGS        += +DD64 
SOLDFLAGS     += +DD64 
LDFLAGS       += +DD64 
else
CFLAGS        += +DD32 
SOLDFLAGS     += +DD32 
LDFLAGS       += +DD32 
endif

ifneq ($(BUILD_ARCH),ia64)
CFLAGS        += +DAportable  # +DAportable is applicable for PA-RISK hardware only 
endif
endif

ifeq ($(CXX),aCC)
STATICF        = -N
SHAREDF        = -b -lrt
CXXFLAGS      += -Ag++

ifeq ($(x64),on)
LDXX	       = $(CXX)
CXXFLAGS      += +DD64 
SOCXXFLAGS    += +DD64
LDCXXFLAGS    += +DD64 
else
CXXFLAGS      += +DD32 
SOCXXFLAGS    += +DD32
LDCXXFLAGS    += +DD32
endif
endif

ifeq ($($(MCO_SIDE)_PLATFORM),$(BUILD_PLATFORM))
SETTINGS_APPLIED=yes
endif

endif

ifeq ($(BUILD_PLATFORM),ADS)
PLATFORM_ID    = -D_ADS
PTHREADLIB     =
PLATFORMLIB    =
SOCKETLIB      =
CC             = armcc
CXX            = armcpp
AR             = armar
MCO_LIB_DYNAMIC= disabled
MCO_SHAREDMEM  = disabled
OPTIMIZEF_SPEED= -O2
COMMONFLAGS   += -DMCO_CFG_EXTENDABLE_DIRTY_PAGE_BITMAP=0

SETTINGS_APPLIED=yes
endif


## Setting up x64 defines --------------------------------

ifeq ($(x64),on)
ARCH_FLAGS        += -DMCO_PLATFORM_X64
endif

## -------------------------------------------------------

ifneq ($(SETTINGS_APPLIED),yes)
$(error Unable to apply build settings)
endif

## --------------------------------------------------------------------
## Creating special file for build system if needed (x64|x32_arch_binaries)
ifeq ($(SHOW_X64_ARCH),on)

## Creating arch file
ifeq ($(shell rm -rf $(MCO_ROOT)/x64_arch_binaries; rm -rf $(MCO_ROOT)/x32_arch_binaries),dummy)
endif

ifeq ($(x64),on)
ifeq ($(shell touch $(MCO_ROOT)/x64_arch_binaries),dummy)
endif
else
ifeq ($(shell touch $(MCO_ROOT)/x32_arch_binaries),dummy)
endif
endif

endif
## -------------------------------------------------------------------- 

ifeq ($(MCO_LARGE_DATABASE_SUPPORT),on)
MCO_CFG_OVERRIDE       += -DMCO_LARGE_DATABASE_SUPPORT
endif

## Dealing with debug and optimization --------------------------------
ifeq ($(OPTIMIZE),size)
OPTIMIZEFLAGS  = $(OPTIMIZEF_SIZE)
else
OPTIMIZEFLAGS  = $(OPTIMIZEF_SPEED)
endif
ifdef DEBUG
DEBUGFLAGS     = $(DEBUGF) -DMCO_DEBUG_DISK_CACHE
OPTIMIZEFLAGS  = 
else
LDCXXFLAGS    += $(LDCXXSTRIPF)
LDFLAGS       += $(LDSTRIPF)
SOFLAGS       += $(LDSTRIPF)
endif

## Pretty build log ---------------------------------------------------
ifndef SHOW_BUILD_LOG
QUIET_COMPILE  =@echo Compiling $< ...
QUIET_FINALIZE =@echo Building $(MCO_TITLE) ... ; \
cat $(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX) | grep 'MCO-MESSAGE' | sed -e 's/.*MCO-MESSAGE *//'
QUIET_PREFIX   =@
#QUIET_SUFFIX   =1>>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX) 2>>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
QUIET_SUFFIX   = >>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX) 2>&1
MAKEFLAGS     += --no-print-directory
else
QUIET_COMPILE  =
QUIET_FINALIZE =
QUIET_PREFIX   =
QUIET_SUFFIX   = 
#QUIET_SUFFIX   = 2>&1 | tee -a $(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
endif

## Compilation rules -------------------------------------------------
MCO_OBJ_DIR      := $(addsuffix $(MCO_ARCH_SFX),$(MCO_OBJ_DIR))

objdir = $(addprefix $(MCO_OBJ_DIR)/,$(filter %.o,$(notdir $(1:%.c=%$(MCO_OBJ_VSFX).o)))) $(addprefix $(MCO_OBJ_DIR)/,$(filter %.o,$(notdir $(1:%.cpp=%$(MCO_OBJ_VSFX).o))))

OBJ = $(call objdir,$(SRC))
ifeq ($(MCO_LIB_DYNAMIC),enabled)
OBJ_L         = $(OBJ:.o=.lo)
 else
OBJ_L         =
endif

.make_obj_dir:
	@sh -c "if [ ! -d $(MCO_BUILD_LOG_DIR) ] ; then mkdir $(MCO_BUILD_LOG_DIR); exit 0; fi"
	@echo "    PROJECT NAME: $(MCO_TITLE)">$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
ifndef SHOW_BUILD_LOG
	@echo " RUNTIME_VERSION: $(shell $(MCO_VERSION))">$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "        MCO_SIDE: $(MCO_SIDE)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "             SRC: $(SRC)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "          MCO_RT: $(MCO_RT)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "              CC: $(CC)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "             CXX: $(CXX)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "          CFLAGS: $(CFLAGS)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "        CXXFLAGS: $(CXXFLAGS)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "              LD: $(LD)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "           LDCXX: $(LDCXX)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "         LDFLAGS: $(LDFLAGS)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "      LDCXXFLAGS: $(LDCXXFLAGS)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "MCO_CFG_OVERRIDE: $(MCO_CFG_OVERRIDE)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "     MCO_INCLUDE: $(MCO_INCLUDE)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "      PTHREADLIB: $(PTHREADLIB)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "     PLATFORMLIB: $(PLATFORMLIB)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "       SOCKETLIB: $(SOCKETLIB)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo "            PATH: $(PATH)">>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo >>$(MCO_BUILD_LOG_DIR)/$(MCO_TITLE)$(MCO_LOGFILE_SFX)
	@echo
	@echo Project: $(MCO_TITLE)
endif
	@sh -c "if [ ! -d $(MCO_OBJ_DIR) ] ; then mkdir $(MCO_OBJ_DIR); exit 0; fi"
	@sh -c "if [ ! -d $(MCO_BIN) ] ; then mkdir $(MCO_BIN); exit 0; fi"
ifeq ($(MCO_SIDE),TARGET)
	@sh -c "if [ ! -d $(MCO_BIN_SO) ] ; then mkdir $(MCO_BIN_SO); exit 0; fi"
	@sh -c "if [ -d $(MCO_ODBC) -a ! -d $(MCO_ODBC_BIN) ] ; then mkdir $(MCO_ODBC_BIN); exit 0; fi"
	@sh -c "if [ -d $(MCO_ODBC) -a ! -d $(MCO_ODBC_BIN_SO) ] ; then mkdir $(MCO_ODBC_BIN_SO); exit 0; fi"
endif

.clear_obj_dir:
	@sh -c "if [ -d $(MCO_OBJ_DIR) ] ; then rm -f $(MCO_OBJ_DIR)/*; exit 0; fi"

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).o: %.cpp
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CXX) $(CXXFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CXXCOMPF) $< $(CXXOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).lo: %.cpp
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CXX) $(SOCXXFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CXXCOMPF) $< $(CXXOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).o: %.c
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CC) $(CFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CCCOMPF) $< $(CCOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).o: $(MCO_OBJ_DIR)/%.c
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CC) $(CFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CCCOMPF) $< $(CCOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).lo: %.c
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CC) $(CFLAGS) $(SOCFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CCCOMPF) $< $(CCOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).o: $(MCO_ROOT)/platform/%.c
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CC) $(CFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CCCOMPF) $< $(CCOUTPUTF) $@ $(QUIET_SUFFIX)

$(MCO_OBJ_DIR)/%$(MCO_OBJ_VSFX).o: $(MCO_ROOT)/src/%.c
	$(QUIET_COMPILE)
	$(QUIET_PREFIX)$(CC) $(CFLAGS) $(MCO_CFG_OVERRIDE) $(MCO_INCLUDE) $(CCCOMPF) $< $(CCOUTPUTF) $@ $(QUIET_SUFFIX)

ifndef SHOW_BUILD_LOG
.remove_obj_dir:
	@echo Removing temporary files for $(MCO_TITLE) ...
	@sh -c "if [ -d $(MCO_OBJ_DIR) ] ; then rm -rf $(MCO_OBJ_DIR); else exit 0; fi"
	@sh -c "if [ -d $(addsuffix $(DISK_SFX),$(MCO_OBJ_DIR)) ] ; then rm -rf $(addsuffix $(DISK_SFX),$(MCO_OBJ_DIR)); else exit 0; fi"
	@sh -c "if [ -d $(addsuffix $(MEMORY_SFX),$(MCO_OBJ_DIR)) ] ; then rm -rf $(addsuffix $(MEMORY_SFX),$(MCO_OBJ_DIR)); else exit 0; fi"
else
.remove_obj_dir:
	sh -c "if [ -d $(MCO_OBJ_DIR) ] ; then rm -rf $(MCO_OBJ_DIR); else exit 0; fi"
	sh -c "if [ -d $(addsuffix $(DISK_SFX),$(MCO_OBJ_DIR)) ] ; then rm -rf $(addsuffix $(DISK_SFX),$(MCO_OBJ_DIR)); else exit 0; fi"
	sh -c "if [ -d $(addsuffix $(MEMORY_SFX),$(MCO_OBJ_DIR)) ] ; then rm -rf $(addsuffix $(MEMORY_SFX),$(MCO_OBJ_DIR)); else exit 0; fi"

endif

.show_compile_settings:
	@echo MCO_SIDE=$(MCO_SIDE)
	@echo $(MCO_SIDE)_ARCH=$($(MCO_SIDE)_ARCH)
	@echo SRC=$(SRC)
	@echo OBJ=$(OBJ)
	@echo CC=$(CC)
	@echo CFLAGS=$(CFLAGS)
	@echo LDFLAGS=$(LDFLAGS)
	@echo CXX=$(CXX)
	@echo CXXFLAGS=$(CXXFLAGS)
	@echo LCXXDFLAGS=$(LCXXDFLAGS)
	@echo MCOCOMP=$(MCOCOMP)
	@echo MCO_INCLUDE=$(MCO_INCLUDE)
	@echo MCO_CFG_OVERRIDE=$(MCO_CFG_OVERRIDE)
	@echo MCO_OBJ_DIR=$(MCO_OBJ_DIR)
	@echo MCO_BIN=$(MCO_BIN)
	@echo MCO_BUILDRT_SFX=$(MCO_BUILDRT_SFX)
	@echo MCO_CFG_SUFFIX_A=$(MCO_CFG_SUFFIX_A)
	@echo MCO_CFG_SUFFIX_SO=$(MCO_CFG_SUFFIX_SO)
	@echo MCO_RTLIB=$(MCO_RTLIB)

